#include <vector>
#include<algorithm>
using namespace std;
class Solution {
public:
    int matrixScore(vector<vector<int>>& A) {
        int res = 0;
        int rows = A.size();
        if (rows < 1)
            return 0;
        int cols = A[0].size();
        for (int c = 0; c < cols; ++c) {
            int num = 0;
            for (int r = 0; r < rows; ++r) {
                num += A[r][c] ^ A[r][0];
            }
            res += (max(num, rows - num)) << (cols - c-1);
        }
        return res;
    }
};